class Solution
{
public:
    vector<int> findBall(vector<vector<int>> &grid)
    {
        int m = grid.size();
        int n = grid[0].size();
        vector<int> result(n);
        for (int beginCol = 0; beginCol < n; ++beginCol)
        {
            int col = beginCol;
            int row = 0;
            while (row < m)
            {
                if (grid[row][col] == 1)
                {
                    if (col == n - 1 || grid[row][col + 1] == -1)
                    {
                        result[beginCol] = -1;
                        break;
                    }
                    else
                    {
                        ++col;
                        ++row;
                    }
                }
                else
                {
                    if (col == 0 || grid[row][col - 1] == 1)
                    {
                        result[beginCol] = -1;
                        break;
                    }
                    else
                    {
                        --col;
                        ++row;
                    }
                }
            }
            if (row == m)
            {
                result[beginCol] = col;
            }
        }
        return result;
    }
};